<div class="SipeiMain_r fr">
    <h2 class="clearfix fonts_18 height45 fontc_444"><?php echo $this->title; ?></h2>
    <div class="clearfix back_bgf border_3 border_c pr30 pt20 pb20 height32 fontc_666">
        <form class="clearfix pb10" action="<?php echo $this->createUrl('/problem/question/index') ?>" method="get">
            <table with="100%">
                <tbody>
                    <tr>
                        <td width="134" align="right" class="pt10 pr2">所属考试项目：</td>
                        <td width="250" class="pt10">
                            <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                                <span class="fl select_shelter">
                                    <select class="fl fontc_666" name="exam_id" id="exam_id">
                                        <option value="0">请选择</option>
                                        <?php
                                        if ($exam):
                                            foreach ($exam as $one):
                                                ?>
                                                <option value="<?php echo $one['exam_id']; ?>" <?php if ($one['exam_id'] == $search['exam_id']): ?>selected<?php endif; ?>><?php echo $one['exam_term_name']; ?></option>
                                                <?php
                                            endforeach;
                                        endif;
                                        ?>
                                    </select>
                                </span>
                            </span>
                        </td>
                        <td width="103" align="right" class="pt10 pr2">所属科目：</td>
                        <td width="151" class="pt10">
                            <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                                <span class="fl select_shelter select_shelter2">
                                    <select class="fl fontc_666" name="subject_id"  id="subject_id">
                                        <option value="0">请选择</option>
                                        <?php
                                        if ($subjectall):
                                            foreach ($subjectall as $one):
                                                ?>
                                                <option value="<?php echo $one['subject_id']; ?>" <?php if ($one['subject_id'] == $search['subject_id']): ?>selected<?php endif; ?>><?php echo $one['subject_name']; ?></option>
                                                <?php
                                            endforeach;
                                        endif;
                                        ?>
                                    </select>
                                </span>
                            </span>
                        </td>
                        <td width="126" align="right" class="pt10"><input type="submit" value="查询" class="b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" /></td>
                    </tr>
                    <tr>
                        <td width="103" align="right" class="pt10 pr2">题型：</td>
                        <td width="151" class="pt10">
                            <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                                <span class="fl select_shelter select_shelter2">
                                    <select class="fl fontc_666" name="subject_num"  id="subject_num">
                                        <option value="">请选择</option>
                                    </select>
                                </span>
                            </span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div class="clearfix back_bgf border_c mt15 pt20 pb20">
        <div class="clearfix pb20 pl30">
            <input type="button" onclick="questionadd()" value="新增"  style="margin-right:30px;" class="fr b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
            <input type="button" onclick="alladd()" value="批量新增" class="fr b_a_n border_3 mr20 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
            <input type="button" value="删除"  onclick="delete_all()" class="fl b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
        </div>
        <form>
            <table class="height40" width="100%">
                <thead class="back_bgf5 fontc_666">
                    <tr>
                        <th width="40" align="right" class="m_hr_t m_hr_b pr10"><input type="checkbox" class="checkboxs"></th>
                        <th width="70" align="center" class="m_hr_t m_hr_b pl10">题号</th>
                        <th width="230" align="center" class="m_hr_t m_hr_b">考试项目</th>
                        <th width="90" align="center" class="m_hr_t m_hr_b">所属科目</th>
                        <th width="120" align="center" class="m_hr_t m_hr_b">所属题型</th>
                        <th width="150" align="center" class="m_hr_t m_hr_b">阅卷教师</th>
                        <th width="90" align="center" class="m_hr_t m_hr_b">操作</th>
                    </tr>
                </thead>
                <tbody class="fontc_444">
                    <?php if ($data): foreach ($data as $one): ?>
                            <tr>
                                <td align="right" class="m_hr_b pr10"><input type="checkbox" name="deleteAll[]" value="<?php echo $one['id']; ?>" class="checkbox"></td>
                                <td align="center" class="m_hr_b fontc_666 pl10"><?php echo $one['num_id']; ?></td>
                                <td align="center" class="m_hr_b"><?php echo $one['exam_term_name']; ?></td>
                                <td align="center" class="m_hr_b"><?php echo $one['subject_name']; ?></td>
                                <td align="center" class="m_hr_b"><?php echo $one['question_name']; ?></td>
                                <td align="left" class="m_hr_b pl10 height20 pt8 pb8"><?php
                                    $str_name = "";
                                    if (isset($one['teacher'])) {
                                        $sum = count($one['teacher']);
                                        foreach ($one['teacher'] as $key => $num) {
                                            $str_name .=$num['teacher_name'];
                                            if (($sum - 1) != $key) {
                                                $str_name .="、";
                                            }
                                        }
                                    }
                                    echo $str_name;
                                    ?></td>
                                <td align="center" class="m_hr_b">
                                    <a onclick="editquestion(<?php echo $one['id']; ?>)" class="mr10"><img src="/themes/default/images/Sipei/edit.png" class="cursor" title="编辑"/></a>
                                    <a onclick="delquestione(<?php echo $one['id']; ?>, $(this))"><img src="/themes/default/images/Sipei/delate.png" class="cursor" title="删除"/></a>
                                </td>
                            </tr>
                            <?php
                        endforeach;
                    else:
                        ?>
                        <tr>
                            <td colspan='6' class="pl30">当前没有您要的数据存在!</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </form>
        <?php $this->renderPartial('//partial/partial_pager', array('pages' => $pages, "url" => $pageUrl)); ?>
    </div>
</div>

<script type="text/javascript" >

    var exam_id = '<?php echo $search['exam_id']; ?>';
    var sub_id = '<?php echo $search['subject_id']; ?>';
    var subject_num = '<?php echo $search['subject_num']; ?>';

    var api;
    function questionadd(){
        api = $.dialog({
            lock: true,
            fixed: true,
            title: "新增",
            width: 500,
            height: 500,
            max: false,
            min: false
        });
        $.get('/problem/question/questionadd', function(data) {
            api.content(data);
        });
    }

    function delete_all(){
        var aa='';
        $("input[name='deleteAll[]']:checkbox:checked").each(function(){
            aa+=$(this).val()+',';
        });
        if(aa == ''){
            $.dialog.alert("请选择要删除条目");
            return false;
        }
        $.dialog.confirm('确定删除所选数据吗', function() {
            aa+=0;

            $.get('/problem/question/delete_all', {id: aa}, function(data) {
                location.reload();
            });
        });
    }

    function alladd(){
        api = $.dialog({
            lock: true,
            fixed: true,
            title: "新增",
            width: 500,
            height: 450,
            max: false,
            min: false
        });
        $.get('/problem/question/alladd', function(data) {
            api.content(data);
        });
    }
    
    function delquestione(id, $this) {
        $.dialog.confirm('确定删除吗', function() {
            $.get('/problem/question/delquestione', {id: id}, function(data) {
                if (data == 1) {
                    $this.parents("tr").remove();
                } else {
                    alert("删除失败");
                }
            });
        });
    }
    
    function editquestion(id){
        api = $.dialog({
            id: 'testID2',
            lock: true,
            fixed: true,
            title: "编辑",
            width: 500,
            height: 500,
            max: false,
            min: false
        });
        $.get('/problem/question/questionedit', {id: id}, function(data) {
            api.content(data);
        });
    }
    
    $(function() {
        $(".checkboxs").click(function() {
            var checkedS = $(this).attr("checked");
            if (checkedS) {
                $(".checkbox").attr("checked", true)
            } else {
                $(".checkbox").removeAttr("checked")
            }
        });
        
        
        $("#exam_id").change(function(){    
            var exam_id = $(this).val();
            _getsubject(exam_id);
        });
        $("#subject_id").change(function(){
           
            var subject_id = $(this).val();
            _getsubjectNum(subject_id,0); 
           
        });

        function _getsubject(exam_id){

            if(exam_id>0){
                $.post('/question_collect/default/ajaxvalue', {id: exam_id}, function(result) {
                    var dataObj = eval("(" + result + ")");//转换为json对象
                    var subjectstr = '';
                    subjectstr += "<option value='0'>请选择</option>"
                    $.each(dataObj, function(i, item) {
                        subjectstr += "<option value='" + item.subject_id + "'>" + item.subject_name + "</option>"
                    });
                    $("#subject_id").html(subjectstr);
                });
            }
        }
        function _getsubjectNum(sub_id,sub_num){
            if(sub_id>0){
                $.post('/question_collect/default/sujectquestions', {subject_id: sub_id}, function(result) {
                    var obj = $.parseJSON(result), newHtml = "";
                    newHtml += "<option value='0'>请选择</option>";
                    $.each(obj, function(i, item) {
                        var sd = '';
                        if(sub_num == i){
                            sd = 'selected';
                        }
                        newHtml += "<option value='" + i + "' "+ sd +">" + item + "</option>"
                    })
                    $("#subject_num").html(newHtml);
                });
            }
        }
        _getsubjectNum(sub_id,subject_num);
    });

    
</script>